<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
    <script>

        var str = "     你好，我      很好！      ";
        console.log(str);
//        console.log(str.trim());
        console.log(trim(str));

        function trim(str){
            var aaa = str.replace(/(^\s+)|(\s+$)/g,"");
            return aaa;
        }


        //面向对象学习
//        String.prototype.aaa = function () {
//            var aaa = str.replace(/(^\s+)|(\s+$)/g,"");
//            return aaa;
//        }
//        console.log(str.aaa());


		var str = "   sfj    sdfj    ";
		console.log(str);
		console.log(trim(str));
		
		function trim(str){
			var aaa = str.replace(/(^\s+)|(\s+$)/g,"");
			return aaa;
		}
		
		String.prototype.aaa = function () {
			var aaa = str.replace(/(^\s+)|(\s+$)/g,"");
			return aaa;
		}
		console.log(str.aaa());
    </script>
</body>
</html>